import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { FormatResponseInterceptor } from './format-response.interceptor';
import { InvokeRecordInterceptor } from './invoke-record.interceptor';
import { UnLoginFilter } from './unlogin.filter';
import { CustomExceptionFilter } from './custom-exception.filter';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.useGlobalPipes(new ValidationPipe()); // Enable global validation pip
  app.useGlobalInterceptors(new FormatResponseInterceptor()); // 启用响应拦截器
  app.useGlobalInterceptors(new InvokeRecordInterceptor()); // 记录请求日志和用户信息
  app.useGlobalFilters(new UnLoginFilter()); // 未登录结构统一报错
  app.useGlobalFilters(new CustomExceptionFilter()); // 修改报错统一格式
  app.enableCors();

  await app.listen(3000);
}
bootstrap();
